{%set solrFileName="jobsdb_solr"%}
{% if 0==1 %}
Copy solr file:
  file.managed:
    - name: /tmp/{{solrFileName}}.zip
    - source: /srv/files/{{solrFileName}}.zip
    - unless: test -f /tmp/{{solrFileName}}.zip

unzip solr:
  cmd.run:
    - name: |
        unzip /tmp/{{solrFileName}}.zip -d /opt/
        cd /opt/{{solrFileName}}
        bin/solr start
    - unless: test -d /opt/{{solrFileName}}
{%endif%}

unzip solr:
  archive.extracted:
    - name: /opt/
    - source: /srv/files/{{solrFileName}}.zip
    - archive_format: zip
    - tar_options: unzip
    - if_missing: /opt/{{solrFileName}}
    - unless: test -d /opt/{{solrFileName}}

{% if 1==1 %}
{% for key, value in salt["pillar.get"]("solr:update:talentsearch", {}).items() %}
{% for country in value %}
Update solr ts_{{key}}_{{country}}:
  file.managed:
    - name: /opt/{{solrFileName}}/solr/ts_{{key}}_{{country}}/conf/schema.xml
    - source: salt://solr/files/talentsearch.schema.xml
{% endfor %}
{% endfor %}

{% for key, value in salt["pillar.get"]("solr:update:talentsearch_status", {}).items() %}
{% for country in value %}
Update solr ts_{{key}}_{{country}}_status:
  file.managed:
    - name: /opt/{{solrFileName}}/solr/ts_{{key}}_{{country}}_status/conf/schema.xml
    - source: salt://solr/files/talentsearch_status.schema.xml
{% endfor %}
{% endfor %}

{% for key, value in salt["pillar.get"]("solr:update:jobad", {}).items() %}
{% for country in value %}
Update solr jobad_{{key}}_{{country}}:
  file.managed:
    - name: /opt/{{solrFileName}}/solr/jobad_{{key}}_{{country}}/conf/schema.xml
    - source: salt://solr/files/jobad.schema.xml
{% endfor %}
{% endfor %}

#solr process in background, and need run the keyboard 'ctrl+c' to quit 'salt-call' command
restart solr:
  cmd.run:
    - name: |
        cd /opt/{{solrFileName}}
        {% if salt['status.pid']('java -jar start.jar') != '' %}
        kill {{salt['status.pid']('java -jar start.jar')}}
        {% endif %}
        nohup java -jar start.jar >/dev/null &
{% endif %}
